#include "calendardialog.h"
#include <QMessageBox>
#include "ui_calendardialog.h"

CalendarDialog::CalendarDialog(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::CalendarDialog)
{
    ui->setupUi(this);

    // 连接信号和槽
    // connect(ui->confirmButton, &QPushButton::clicked, this, &CalendarDialog::onConfirmClicked);
    // connect(ui->cancelButton, &QPushButton::clicked, this, &CalendarDialog::onCancelClicked);
    // 连接 QCalendarWidget 的 selectionChanged 信号
    connect(ui->calendarWidget, &QCalendarWidget::selectionChanged, this, [this]() {
        QDate selectedDate = ui->calendarWidget->selectedDate();
        emit dateSelected(selectedDate); // 发射信号，发送选中的日期
        this->accept();                  // 关闭弹窗
    });
}

CalendarDialog::~CalendarDialog()
{
    delete ui;
}

QDate CalendarDialog::getSelectedDate() const
{
    return selectedDate;
}

// void CalendarDialog::onConfirmClicked() {
//     // 获取当前选择的日期
//     selectedDate = ui->calendarWidget->selectedDate();
//     QMessageBox::information(this, "选择的日期", "您选择的日期是: " + selectedDate.toString("yyyy-MM-dd"));
//     accept(); // 关闭弹窗并返回 QDialog::Accepted
// }

// void CalendarDialog::onCancelClicked() {
//     reject(); // 关闭弹窗并返回 QDialog::Rejected
// }
